/**
 * 项目名：化工企业安全生产信息化管理平台
 * 日期：    2020-03-01 22:19:08
 * Copyright (c) 2015- -版权所有
 */

package com.joysuch.wwyt.edu.repository;

import java.util.List;

import com.joysuch.wwyt.edu.entity.EduQuestionItem;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;

/**
 * EduQuestionItemDao
 *
 */
public interface EduQuestionItemDao
        extends JpaRepository<EduQuestionItem, Long>, QuerydslPredicateExecutor<EduQuestionItem> {
    public Page<EduQuestionItem> findAll(Specification<EduQuestionItem> spec, Pageable pageable);

    public EduQuestionItem save(EduQuestionItem bean);

    public void delete(EduQuestionItem bean);

    @Modifying
    @Query("update EduQuestionItem set deleteFlag='1' where questionId=?1 and id not in (?2)")
    void clearRemovedItems(Long questionId, List<Long> reservedIds);

    @Modifying
    @Query("update EduQuestionItem set deleteFlag='1' where questionId=?1")
    void clearRemovedItems(Long questionId);

    List<EduQuestionItem> findByQuestionIdOrderByIndexNoAsc(Long questionId);

    void deleteByQuestionId(Long id);

    @Query("SELECT eq  from EduQuestionItem eq where eq.questionId in (?1)")
    List<EduQuestionItem> findByQuestionIds(List<Long> qIds);

    @Query("SELECT eq  from EduQuestionItem eq where eq.questionId = ?1")
    List<EduQuestionItem> getByItem(Long id);
}
